package com.cuanbo.dualscreenteachfu.activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.cuanbo.dualscreenteachfu.R;
import com.cuanbo.dualscreenteachfu.adapter.ImgAdapter;
import com.cuanbo.dualscreenteachfu.base.LHBaseActivity;
import com.cuanbo.dualscreenteachfu.utils.BroadcastUtil;
import com.cuanbo.dualscreenteachfu.utils.DateUtil;

import java.util.Date;

public class FileActivity extends LHBaseActivity {
    private View rootView;
    private RecyclerView rvImg;
    private ImgAdapter imgAdapter;
    private TextView tvDate;
    private long time;
    private TextView tvCapture;
    private TextView tvVideo;
    private RelativeLayout rlCapture;
    private RelativeLayout rlVideo;
    private int type=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        rootView= LayoutInflater.from(this).inflate(R.layout.activity_file,null);
        setContentView(rootView);
        init();
    }

    public void init(){
        initView();
        initImgAdapter();
    }

    public void initView() {
        rvImg = rootView.findViewById(R.id.rvImg);
        tvDate = rootView.findViewById(R.id.tvDate);
        tvCapture = rootView.findViewById(R.id.tvCapture);
        tvVideo = rootView.findViewById(R.id.tvVideo);

        rlCapture = rootView.findViewById(R.id.rlCapture);
        rlVideo = rootView.findViewById(R.id.rlVideo);
    }

    private void initImgAdapter() {
        rvImg.setLayoutManager(new GridLayoutManager(this, 2));
        imgAdapter = new ImgAdapter();
        rvImg.setAdapter(imgAdapter);
        time=new Date().getTime();
        tvDate.setText(DateUtil.fmtYMD());
        imgAdapter.refurshData(DateUtil.fmtYMD(),type);
    }
    
    @Override
    public void requestData() {
        
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        BroadcastUtil.sendBroadcastToZhuScreen(13);
    }

    /**
     *上一页
     */
    public void upDate(View v) {
        time=time-24*60*60*1000;
        String date= DateUtil.fmtYMD(time);
        tvDate.setText(date);
        imgAdapter.refurshData(date,type);
    }

    /**
     *下一页
     */
    public void nextDate(View v) {
        time=time+24*60*60*1000;
        String date=DateUtil.fmtYMD(time);
        tvDate.setText(date);
        imgAdapter.refurshData(date,type);
    }

    /**
     *返回
     */
    public void btnBack(View v) {
        finish();
    }

    /**
     *图片
     */
    public void btnCapture(View v) {
        type=0;
        rlCapture.setBackgroundResource(R.drawable.btn_ck_bg);
        tvCapture.setTextColor(0xffffffff);
        rlVideo.setBackgroundResource(R.drawable.btn_unck_bg);
        tvVideo.setTextColor(0xffc2d3f1);
        time=new Date().getTime();
        tvDate.setText(DateUtil.fmtYMD());
        imgAdapter.refurshData(DateUtil.fmtYMD(),type);
    }

    /**
     *视频
     */
    public void btnVideo(View v) {
        type=1;
        rlCapture.setBackgroundResource(R.drawable.btn_unck_bg);
        tvCapture.setTextColor(0xffc2d3f1);
        rlVideo.setBackgroundResource(R.drawable.btn_ck_bg);
        tvVideo.setTextColor(0xffffffff);
        time=new Date().getTime();
        tvDate.setText(DateUtil.fmtYMD());
        imgAdapter.refurshData(DateUtil.fmtYMD(),type);
    }
}